package com.verlet.springbootdemo.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;


/**
 * servlet3.0 @WebFilter不支持过滤器顺序配置<br>
 * 推荐使用 filterRegistrationBean 配置Filter
 *
 * @author verlet
 * @date 2020/4/8
 */
@Slf4j
//@WebFilter(urlPatterns = "/*", filterName = "myFilter")
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info(MyFilter.class + "过滤器初始化=========");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        log.info(MyFilter.class + "  " + httpServletRequest.getRequestURI() + " 开始执行========");
        chain.doFilter(httpServletRequest, response);
        log.info(MyFilter.class + "执行完成=========");
    }

    @Override
    public void destroy() {
        log.info(MyFilter.class + "销毁===========");

    }
}
